package com.example.administrator.waitan.hot.today;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.tools.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/12.
 */
public class TodayBaseAdapter extends BaseAdapter {
    private Context context;
    private List<TodayInfo> data;
    private ImageLoader imageLoader;
    private ImageLoader.ImageCache imageCache;
    private LruCache<String, Bitmap> lruCache;
    private RequestQueue queue;

    public TodayBaseAdapter(Context context, List<TodayInfo> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0 ;
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyViewHolder myViewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_lv_today, null);
            myViewHolder = new MyViewHolder();
            myViewHolder.title = (TextView) view.findViewById(R.id.tv_item_today_title);
            myViewHolder.pic = (ImageView) view.findViewById(R.id.iv_item_today_pic);
            view.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) view.getTag();
        }
        myViewHolder.title.setText(data.get(i).getTitle());
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(myViewHolder.pic, R.mipmap.mi_icon, R.mipmap.mi_icon);
        VolleySingleton.getImageLoader().get(data.get(i).getThumbnail(), listener);
        return view;
    }

    private class MyViewHolder {
        TextView title;
        ImageView pic;
    }
}
